package org.dromara.lessor.controller;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.admin.domain.bo.ContractBillBo;
import org.dromara.admin.domain.vo.ContractBillVo;
import org.dromara.admin.service.IContractBillService;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 出租方租金账单信息
 *
 * @author Lion Li
 * @date 2025-09-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/lessor/contractBill")
public class LessorContractBillController extends BaseController {

    private final IContractBillService contractBillService;

    /**
     * 出租方获取自己租金账单信息列表(财务列表)
     */
//    @SaCheckPermission("lessor:contractBill:list")
    @GetMapping("/lessorMyList")
    public TableDataInfo<ContractBillVo> lessorMyList(ContractBillBo bo, PageQuery pageQuery) {
        Long userId = LoginHelper.getUserId();
        if (userId == null){
            throw new ServiceException("用户未登录");
        }
        bo.setLessorUserId(userId);
        return contractBillService.queryPageLessorMyList(bo, pageQuery);
    }

    /**
     * 导出租金账单信息列表
     */
//    @SaCheckPermission("lessor:contractBill:export")
    @Log(title = "租金账单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ContractBillBo bo, HttpServletResponse response) {
        List<ContractBillVo> list = contractBillService.queryList(bo);
        ExcelUtil.exportExcel(list, "租金账单信息", ContractBillVo.class, response);
    }

    /**
     * 获取租金账单信息详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("lessor:contractBill:query")
    @GetMapping("/{id}")
    public R<ContractBillVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(contractBillService.queryById(id));
    }
}
